/**
 * 
 */
package com.cipe.cmrs.converter;

import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.converter.ConverterRegistry;

import com.cipe.cmrs.bean.PayeeBean;
import com.cipe.cmrs.model.Payee;

class PayeeToPayeeBean implements Converter<Payee, PayeeBean> {

    private ConverterRegistry converterRegistry;

    /**
     * @param converterRegistry
     *            the converterRegistry to set
     */
    public void setConverterRegistry(ConverterRegistry converterRegistry) {
        this.converterRegistry = converterRegistry;
    }

    public void init() {
        converterRegistry.addConverter(this);
    }

    public PayeeBean convert(Payee source) {
        PayeeBean bean = new PayeeBean();
        if (source != null) {
            bean.setAddress1(source.getPayeeAddress1());
            bean.setAddress2(source.getPayeeAddress2());
            bean.setCity(source.getPayeeCity());
            if (source.getPayeestate() != null) {
                bean.setState(source.getPayeestate().getDisplayName());
            }
            bean.setZipCode(source.getPayeeZipCode());
            if (source.getPayeeCountry() != null) {
                bean.setCountry(source.getPayeeCountry().getDisplayName());
            }
            bean.generateCompleteAddress();
        }
        return bean;
    }

}
